﻿
// AKRSDlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "AKRS.h"
#include "AKRSDlg.h"
#include "afxdialogex.h"

#include "CReplyDlg.h"
#include "CSettingsDlg.h"
#include "words.h"


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CAKRSDlg 对话框



CAKRSDlg::CAKRSDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_AKRS_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAKRSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAKRSDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ABOUT, &CAKRSDlg::OnBnClickedAbout)
	ON_BN_CLICKED(IDC_EXIT, &CAKRSDlg::OnBnClickedExit)
	ON_EN_CHANGE(IDC_EDIT, &CAKRSDlg::OnEnChangeEdit)
	ON_BN_CLICKED(IDC_BUTTON_SETTINGS, &CAKRSDlg::OnBnClickedButtonSettings)
END_MESSAGE_MAP()


// CAKRSDlg 消息处理程序

BOOL CAKRSDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

// TODO: 在此添加额外的初始化代码

return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CAKRSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CAKRSDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CAKRSDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CAKRSDlg::OnBnClickedAbout()
{
	// TODO: 在此添加控件通知处理程序代码
	CAboutDlg* pDlg = new CAboutDlg;
	pDlg->DoModal();
}


void CAKRSDlg::OnBnClickedExit()
{
	// TODO: 在此添加控件通知处理程序代码
	exit(EXIT_SUCCESS);
}



void CAKRSDlg::OnEnChangeEdit()
{
	// TODO:  如果该控件是 RICHEDIT 控件，它将不
	// 发送此通知，除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask()，
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	CString ss;
	CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT);
	pEdit1->GetWindowText(ss);
	CString ss1 = ss, ss2 = ss;
	ss2.MakeLower();
	
	bool flag = false;
	for (int i = 0, j = 1; WordList[i] != _T("this is the end"); i++)
	{
		if (WordList[i] == _T("end"))
		{
			j++;
			continue;
		}
		if (SettingsValue[j] == false)continue;
		while (ss2.Find(WordList[i]) != -1)
		{
			if (flag == false)
			{
				CReplyDlg* pDlg = new CReplyDlg;
				pDlg->DoModal();
				flag = true;
			}
			ss.Delete(ss2.Find(WordList[i]), WordList[i].GetLength());
			ss2.Delete(ss2.Find(WordList[i]), WordList[i].GetLength());

		}
	}
	if (ss1 != ss)pEdit1->SetWindowText(ss);
}



BOOL CAboutDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();


	CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_LICENSE);
	CString s = _T("\
MIT License\r\n\
\r\n\
Copyright (c) 2022-2024 apple-ba\r\n\
\r\n\
Permission is hereby granted, free of charge, to any person obtaining a copy\r\n\
of this software and associated documentation files (the \"Software\"), to deal\r\n\
in the Software without restriction, including without limitation the rights\r\n\
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n\
copies of the Software, and to permit persons to whom the Software is\r\n\
furnished to do so, subject to the following conditions:\r\n\
\r\n\
The above copyright notice and this permission notice shall be included in all\r\n\
copies or substantial portions of the Software.\r\n\
\r\n\
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n\
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n\
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n\
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n\
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n\
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n\
SOFTWARE.");


	static CFont font1;
	font1.DeleteObject();
	font1.CreatePointFont(80, _T("新宋体"));
	pEdit->SetFont(&font1);


	pEdit->SetWindowText(s);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


void CAKRSDlg::OnBnClickedButtonSettings()
{
	// TODO: 在此添加控件通知处理程序代码

	CSettingsDlg* pDlg = new CSettingsDlg;
	pDlg->DoModal();
}
